package jp.co.hcs.attendancemanagement.inputtableb.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.hcs.attendancemanagement.action.AMAction;
import jp.co.hcs.attendancemanagement.data.entity.Project;
import jp.co.hcs.attendancemanagement.inputtableb.logic.CheckProjectCodeLogic;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class CheckExistProjectCodeAction extends AMAction {
  public ActionForward executeImpl(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String projectCode = request.getParameter("projectCode");
    String seri = (String) request.getParameter("seri");

    if (projectCode == null) {
      return null;
    }

    if (seri == null) {
      return null;
    }

    response.setContentType("text/json");

    CheckProjectCodeLogic logic = CheckProjectCodeLogic.getInstance();
    Project project = logic.checkProjectCodeExisting(projectCode, seri);
    JSONObject jsonObj = JSONObject.fromObject(project);
    PrintWriter pw = response.getWriter();
    pw.write(jsonObj.toString());
    pw.flush();
    pw.close();
    return null;
  }
}
